package gitee.cheungming.modules.governance.task;

import cn.hutool.core.util.RandomUtil;
import gitee.cheungming.modules.governance.domain.ConditionData;
import gitee.cheungming.modules.governance.domain.EnvironmentData;
import gitee.cheungming.modules.governance.domain.EventData;
import gitee.cheungming.modules.governance.service.ConditionService;
import gitee.cheungming.modules.governance.service.EnvironmentService;
import gitee.cheungming.modules.governance.service.EventService;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;
import java.util.concurrent.TimeUnit;

@EnableScheduling
public class IngestionTask {

    @Resource
    ConditionService conditionService;

    @Resource
    EnvironmentService environmentService;

    @Resource
    EventService eventService;

    /**
     * 每30秒执行一次
     */
    @Scheduled(fixedDelay = 30, timeUnit = TimeUnit.SECONDS)
    public void ingestConditionData() {
        List<ConditionData> list = conditionService.createConditionData(10000);
        conditionService.ingestion(list);
    }

    @Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
    void ingestEnvironmentData() {
        List<EnvironmentData> list = environmentService.createData(10000);
        environmentService.ingestion(list);
    }


    @Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
    void ingestion() {
        List<EventData> list = eventService.createData(RandomUtil.randomInt(1000, 10000));
        eventService.ingestion(list);
    }
}
